package com.example.interview.example.bankCallSystem.impl_3;

import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;

//向不同type的客户队列中添加init客户
public class Producer {

    public ArrayBlockingQueue<Consumer> normals;
    public ArrayBlockingQueue<Consumer> vips;
    public ArrayBlockingQueue<Consumer> quicks;

    public void produce() {
        Random random = new Random();
        Random time = new Random();
        int v = 1;
        int q = 1;
        int c = 1;
        try {
            while (true) {
                int type = random.nextInt(10) + 1; //产生1-10
                if (type == 1) {      //机会：1% ； VIP客户 ：快速客户 ：普通客户 =  1 ：3 ：6
                    System.out.println("产生第" + v + "个【vip】客户");
                    vips.put(new Consumer(v++, "vip"));
                } else if (type < 5) {// 2 3 4 机会：3% ；
                    System.out.println("产生第" + q + "个【快速】客户");
                    quicks.put(new Consumer(q++, "快速"));
                } else {              // 5 6 7 8 9 10 机会：6% ；
                    System.out.println("产生第" + c + "个【普通】客户");
                    normals.put(new Consumer(c++, "普通"));
                }

                Thread.sleep(time.nextInt(1000));
            }

        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    public ArrayBlockingQueue<Consumer> getNormals() {
        return normals;
    }

    public void setNormals(ArrayBlockingQueue<Consumer> normals) {
        this.normals = normals;
    }

    public ArrayBlockingQueue<Consumer> getVips() {
        return vips;
    }

    public void setVips(ArrayBlockingQueue<Consumer> vips) {
        this.vips = vips;
    }

    public ArrayBlockingQueue<Consumer> getQuicks() {
        return quicks;
    }

    public void setQuicks(ArrayBlockingQueue<Consumer> quicks) {
        this.quicks = quicks;
    }
}
